package com.uex.dev.manage.admin.vo.user;

import com.uex.dev.manage.admin.enums.UserTypeEnum;
import com.uex.dev.manage.admin.po.UserPO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Optional;

/**
 * @author lzs
 * @create 2024/02/23
 * @description
 */
@Schema(description = "获取用户列表响应参数")
@Data
public class UserPageResp {
    @Schema(description = "用户Id")
    private Integer id;
    @Schema(description = "用户名")
    private String userName;
    @Schema(description = "用户账号")
    private String userAccount;
    @Schema(description = "用户类型")
    private UserTypeEnum userType;
    @Schema(description = "用户类型")
    private String userTypeDesc;

    public static UserPageResp fromPO(UserPO userPO) {
        UserPageResp userPageResp = new UserPageResp();
        BeanUtils.copyProperties(userPO, userPageResp);
        userPageResp.setUserTypeDesc(Optional.ofNullable(userPO.getUserType()).map(UserTypeEnum::getDesc).orElse(""));
        return userPageResp;
    }
}

